/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pos.Driving.Path.Segment;

import javax.vecmath.*;
import pos.Driving.Path.*;

/**
 * 1号线区间1 莘庄-外环路
 * @author Administrator
 */
public class Segment_01_01 extends Segment{

    public Segment_01_01() {
        super(1, "1号线区间1", "莘庄-外环路", "Model.Segments.S01_01"
                , new Point3d(0,0,0));
        this.addOnRailDevice(0, 400, new ATPSpeedSignture(77));
        this.addOnRailDevice(1, 400, new ATPSpeedSignture(35));
        
        this.addOnRailDevice(1, 450, new ATOStationSignture(33,true));
        this.addOnRailDevice(0, 600, new ATOStationSignture(-1,true));
        
        this.addOnRailDevice(1, 10, new RailwayEndder());
        this.addOnRailDevice(0, 10, new RailwayEndder());
        
        this.addSideway(0, 250, "Return", new Sideway(0,0,0,2));
        this.addSideway(1, 350, "Final", new Sideway(1,2,1,1));
        this.addSideway(2, 250, "Return", new Sideway(0,0,2,2));
        this.addSideway(2, 350, "Final", new Sideway(2,2,1,1));
    }

    @Override
    protected void initRail() {
        this.addPathSection(0, 0, 1500, new Followable(){
            public PosPoint makePath(PosPoint pos) {
                PosPoint ppOut=new PosPoint(pos);
                if (ppOut.d>800)
                    ppOut.pos=new Point3d(ppOut.d-300,
                            -14d-15d*Math.sin(-0.5*Math.PI+(ppOut.d-800d)/700d*Math.PI),3);
                else
                    ppOut.pos=new Point3d(ppOut.d-300,1,3);
                    
                ppOut.AngH=0;
                ppOut.AngV=0;
                
                if (ppOut.d>400 && ppOut.d<650)
                    ppOut.PATH_TYPE=PosPoint.PATH_STATION;
                else if(ppOut.d>=900)
                    ppOut.PATH_TYPE=PosPoint.PATH_SINGLE_TUNNEL;
                else 
                    ppOut.PATH_TYPE=PosPoint.PATH_GROUND_R;
                /*if (ppOut.isSideway && ppOut.d>200 && ppOut.d<220)
                    ppOut.path_ID=2;*/
                return ppOut;
            }
        });
        
        this.addPathSection(2, 200, 400, new Followable(){                      //单渡线
            public PosPoint makePath(PosPoint pos) {
                PosPoint ppOut=new PosPoint(pos);
                if (pos.d>250 && pos.d<350){
                    double t=((pos.d-250d)/100d-0.5)*Math.PI,
                            t1=((pos.d+0.1-250d)/100d-0.5)*Math.PI;
                    ppOut.pos=new Point3d(ppOut.d-300,1,-3*Math.sin(t));
                    ppOut.AngV=-Math.atan((Math.sin(t)-Math.sin(t1))/0.1);
                }else{
                    if (pos.d<250)
                        ppOut.pos=new Point3d(ppOut.d-300,1,3);
                    else
                        ppOut.pos=new Point3d(ppOut.d-300,1,-3);
                    ppOut.AngV=0;
                }
                ppOut.AngH=0;
                ppOut.PATH_TYPE=PosPoint.PATH_STATION;
               /* if (ppOut.d>300){
                    ppOut.path_ID=1;
                    //ppOut.isSideway=false;
                }
                else if(ppOut.d<200){
                    ppOut.path_ID=0;
                    //ppOut.isSideway=false;
                }*/
                return ppOut;
            }
        });
        
        
        this.addPathSection(1, 0, 1500, new Followable(){
            public PosPoint makePath(PosPoint pos) {
                PosPoint ppOut=new PosPoint(pos);
                if (ppOut.d>800)
                    ppOut.pos=new Point3d(ppOut.d-300,
                            11+10d*Math.sin(-0.5*Math.PI+(ppOut.d-800d)/700d*Math.PI),-3);
                else
                    ppOut.pos=new Point3d(ppOut.d-300,1,-3);
                ppOut.AngH=0;
                ppOut.AngV=0;
                
                if (ppOut.d>400 && ppOut.d<650)
                    ppOut.PATH_TYPE=PosPoint.PATH_STATION;
                else if (ppOut.d>=1000)
                    ppOut.PATH_TYPE=PosPoint.PATH_SINGLE_LIFT;
                else
                    ppOut.PATH_TYPE=PosPoint.PATH_GROUND;
                /*if (ppOut.isSideway && ppOut.d>280 && ppOut.d<300){
                    ppOut.path_ID=2;
                   // System.out.println(ppOut.d);
                }*/
                return ppOut;
            }
        });
    }

}
